<template>
  <div class="login">
    <hry-header
      title="好融艺平台数据"
      :showBackBtn="false"
      backRouterName="login"
    >
      <span
        class="iconfont icontubiao"
        :class="isShowTable ? '' : 'active'"
        slot="action"
        @click="changeStatus"
      ></span>
      <div slot="content" class="normal-wrapper">
        <md-scroll-view
          ref="scrollView"
          :scrolling-x="false"
          :auto-reflow="true"
          @refreshing="getInfo"
        >
          <md-scroll-view-refresh
            slot="refresh"
            slot-scope="{ scrollTop, isRefreshActive, isRefreshing }"
            :scroll-top="scrollTop"
            :is-refreshing="isRefreshing"
            roller-color="#FD7400"
            :is-refresh-active="isRefreshActive"
          ></md-scroll-view-refresh>
          <keep-alive>
            <component v-bind:is="currentTabComponent" :info="info"></component>
          </keep-alive>
          <md-button
            type="warning"
            round
            style="width: 80%;margin: 20px auto;color: white"
            @click="logout"
            >退出登录</md-button
          >
        </md-scroll-view>
      </div>
    </hry-header>
  </div>
</template>

<script>
import { ScrollView, Icon, Button, ScrollViewRefresh } from "mand-mobile";
export default {
  name: "",
  components: {
    [Icon.name]: Icon,
    [ScrollView.name]: ScrollView,
    [ScrollViewRefresh.name]: ScrollViewRefresh,
    [Button.name]: Button,
    hryHeader: () => import("@/components/contentWrapper/index"),
    hryDraw: () => import("@/components/home/echarts"),
    hryTable: () => import("@/components/home/table")
  },
  data() {
    return {
      isShowTable: true,
      info: {
        allMoney: 0,
        dayMoney: 0,
        alluser: 0,
        authUser: 0,
        dayLogin: 0,
        dayAuth: 0,
        recharge: 0,
        getcash: 0,
        allMemberMoney: 0
      }
    };
  },
  methods: {
    logout() {
      localStorage.removeItem("dtoken");
      this.$router.push({ name: "login" });
    },
    changeStatus() {
      this.isShowTable = !this.isShowTable;
    },
    getInfo() {
      this.$ajax
        .post(this.$api.index, false)
        .then(res => {
          Object.assign(this.info, res.data);
          this.$refs.scrollView.finishRefresh();
        })
        .catch(err => {
          this.$toast.failed(err);
        });
    }
  },
  computed: {
    currentTabComponent() {
      if (this.isShowTable) {
        return "hryTable";
      } else {
        return "hryDraw";
      }
    }
  },
  created() {
    this.getInfo();
  }
};
</script>

<style scoped lang="stylus">
.login {
  height: 100%;
  width: 100%;
  .active{
    color color-primary
  }
}
  .normal-wrapper{
    height 100%
    width 100%
    overflow hidden
    background #f0f0f0
  }
</style>
